﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Text.RegularExpressions;




namespace DotNetNuke.Tests.UI.WatiN.AdministratorTests
{
    [TestFixture]

    public class AdminSiteSettingsTests : ATBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests



        [Test]
        public void Access_Site_Settings()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act            
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");

            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            //Assert
            Assert.IsTrue(settingsPage.PageTitle.InnerHtml.Contains("Site Settings"));
            Assert.IsFalse(settingsPage.SSLSectionLink.Exists);
            Assert.IsFalse(settingsPage.HostSectionLink.Exists);

            //Arrange 
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            LoginPage hostLogin = new LoginPage(homePage);
            hostLogin.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");

            //Assert 
            Assert.IsTrue(settingsPage.PageTitle.InnerHtml.Contains("Site Settings"));
            Assert.IsTrue(settingsPage.SSLSectionLink.Exists);
            Assert.IsTrue(settingsPage.HostSectionLink.Exists);
        }

        [Test]
        public void Change_Portal_Skin_Container()
        {
            if (Directory.Exists(PhysicalPath + @"\Portals\0\Skins\" + SkinName) &&
                Directory.Exists(PhysicalPath + @"\Portals\0\Containers\" + SkinName))
            {
                Directory.Delete(PhysicalPath + @"\Portals\0\Skins\" + SkinName, true);
                Directory.Delete(PhysicalPath + @"\Portals\0\Containers\" + SkinName, true);
            }
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Add A page
            String pageName = "TestPage";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            if (usesRibbonBar)
            {
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel.PageSettingsLink.Click();
            }
            newPage.AdvancedSettingsExpandButton.ClickNoWait();
            if (VersionType.Equals("Community"))
            {
                newPage.PageSkinSelect.Select("MinimalExtropy - Index");
                newPage.PageContainerSelect.Select("MinimalExtropy - Title_Grey");
             }
            else
            {
                newPage.PageSkinSelect.Select("MinimalExtropyPro - Index");
                newPage.PageContainerSelect.Select("MinimalExtropyPro - Title_Grey");
            }
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Add a Skin to the site
            ieInstance.GoTo(SiteURL + "/Admin/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

           

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage siteSettings = new SiteSettingsPage(homePage);
            siteSettings.AppearanceExpandButton.ClickNoWait();
            siteSettings.PortalSkinSiteOption.Checked = true;
            System.Threading.Thread.Sleep(1000);
            siteSettings.PortalSkinSelectList.Select(SkinUsed);
            siteSettings.PortalContainerSiteOption.Checked = true;
            System.Threading.Thread.Sleep(1000);
            siteSettings.PortalContainerSelectList.Select(ContainerUsed);
            siteSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Assert
            ElementContainer<Element> header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));

            //Check the skin and container for the home page
            Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Containers_" + SkinName + "_")))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Skins_" + SkinName + "_")))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);


            String minimalExtropySkinString;
            String minimalExtropyContainerString;
            if (VersionType.CompareTo("Community") == 0)
            {
                minimalExtropySkinString = "Skins_MinimalExtropy_";
                minimalExtropyContainerString = "Containers_MinimalExtropy_";
            }
            else
            {
                minimalExtropySkinString = "Skins_MinimalExtropyPro_";
                minimalExtropyContainerString = "Containers_MinimalExtropyPro_";
            }
            //Check the skin and container for the test page
            ieInstance.GoTo(SiteURL + "/" + pageName + ".aspx");
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropySkinString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyContainerString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
        }

        [Test]
        public void Change_Edit_Skin_Container()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            

            //Add a Skin to the site
            ieInstance.GoTo(SiteURL + "/Host/Extensions.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(SkinPath);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage siteSettings = new SiteSettingsPage(homePage);
            siteSettings.AppearanceSectionLink.Click();
           // siteSettings.EditSkinSiteOption.Checked = true;
            System.Threading.Thread.Sleep(500);
            siteSettings.EditSkinSelectList.Select(SkinUsed);
            //siteSettings.EditContainerSiteOption.Checked = true;
            System.Threading.Thread.Sleep(500);
            siteSettings.EditContainerSelectList.Select(ContainerUsed);
            siteSettings.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Assert
            ElementContainer<Element> header;
            if(homePage.PopUpFrame != null)
            {
                header = (ElementContainer<Element>)homePage.PopUpFrame.Element(Find.ById("Head"));
            }
            else
            {
                header = (ElementContainer<Element>)ieInstance.Element(Find.ById("Head"));
            }
            

            String minimalExtropySkinString = "Skins_DarkKnight";
            String minimalExtropyContainerString = "Containers_DarkKnight";
            //if (VersionType.CompareTo("Community") == 0)
            //{
            //    minimalExtropySkinString = "Skins_MinimalExtropy_";
            //    minimalExtropyContainerString = "Containers_MinimalExtropy_";
            //}
            //else
            //{
            //    minimalExtropySkinString = "Skins_MinimalExtropyPro_";
            //    minimalExtropyContainerString = "Containers_MinimalExtropyPro_";
            //}

            //Check the skin and container for the home page
            Element stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropySkinString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains(minimalExtropyContainerString)))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);

            //Check the skin and container for the page settings page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.EditCurrentPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.PageSettingsLink.Click();
            }
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Containers_" + SkinName + "_")))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
            stylesheet = header.Elements.Filter(Find.ById(s => s.Contains("Skins_" + SkinName + "_")))[0];
            Assert.IsTrue(stylesheet.Exists);
            Assert.IsTrue(stylesheet.GetAttributeValue("rel").CompareTo("stylesheet") == 0);
        }

        [Test]
        public void Change_Body_Background_For_Site()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act            
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            System.Threading.Thread.Sleep(1500);
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AppearanceSectionLink.Click();
            settingsPage.UploadBackgroundImgLink.Click();
            settingsPage.BackgroundImageFileUpload.Set(Path.Combine(TestFilesPath, "Koala.jpg"));
            settingsPage.SaveFileBackgroundLink.Click();
            System.Threading.Thread.Sleep(1500);
            settingsPage.UpdateLink.Click();

            //Assert
            System.Threading.Thread.Sleep(2500);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            Assert.IsTrue(homePage.Body.GetAttributeValue("style").Contains("Koala.jpg"));
        }

        [Test]
        public void Change_Site_Logo()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act            
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AppearanceSectionLink.ClickNoWait();
            settingsPage.UploadLogoImgLink.Click();
            settingsPage.LogoImageFileUpload.Set(Path.Combine(TestFilesPath, "KoalaCropped.jpg"));
            settingsPage.SaveFileLogoLink.Click();
            settingsPage.UpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            Assert.IsTrue(homePage.LogoImage.Src.Contains("KoalaCropped.jpg"));
        }

        [Test]
        public void Change_User_Registration_None()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Act            
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.SecuritySectionLink.Click();
            settingsPage.NoneRegistrationRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            Assert.IsFalse(homePage.RegisterLink.Exists);
        }
        
        [Test]
        public void Add_New_Portal_Alias()
        {
            //Arrange
            string portalAlias = "newPortalAlias";
            IISManager.CreateIISApplication(portalAlias, PhysicalPath);
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);

            //Act 
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PortalAliasesSectionLink.Click();
            settingsPage.AddNewAliasLink.ClickNoWait();
            System.Threading.Thread.Sleep(3000);
            settingsPage.AliasTextBox.Value = ("localhost/" + portalAlias);
            settingsPage.PortalAliasSaveButtonPortal.ClickNoWait();
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(3000);

            //Assert
            ieInstance.GoTo("http://localhost/" + portalAlias);
            Assert.IsTrue(homePage.LogoImage.Exists);
        }

        [Test]
        public void Change_Login_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add A page
            String pageName = "TestPage";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.ClickViewPermissionForRole("All Users");
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/" + pageName + ".aspx");

            //Add an account login module to the page);
            if (!usesRibbonBar)
            {
                controlPanel.AddModuleToPage("", "Account Login");
            }
            else
            {
                ribbonBar.AddModuleToPage("", "Account Login", "Uncategorised");
            }

            //Act
            System.Threading.Thread.Sleep(4000);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.LoginPageSelectList.Select(pageName);
            System.Threading.Thread.Sleep(1000);
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(5000);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginLink.ClickNoWait();
            SiteMenu menu = new SiteMenu(homePage);
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals(pageName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Account Login"));
        }

        [Test]
        public void Change_User_Profile_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add A page
            String pageName = "TestPage";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/" + pageName + ".aspx");

            //Add an account login module to the page
            if (!usesRibbonBar)
            {
                controlPanel.AddModuleToPage("", "ViewProfile");
            }
            else
            {
                ribbonBar.AddModuleToPage("", "ViewProfile", "All Categories");
            }

            //Act
            System.Threading.Thread.Sleep(4000);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.UserProfilePageSelectList.Select(pageName);
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            homePage.RegisterLink.Click();
            SiteMenu menu = new SiteMenu(homePage);
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals(pageName), menu.BreadCrumbSpan.Text);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("ViewProfile"));
        }

        [Test]
        public void Change_Page_Quota()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            bool usesRibbonBar = false;

            //First find out the current number of pages 
            ieInstance.GoTo(SiteURL + "/Admin/Pages.aspx");
            AdminPagesPage pages = new AdminPagesPage(homePage);
            //int numPages = pages.PagesSelectList.Options.Count;
            int numPages = 26;

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            System.Threading.Thread.Sleep(2500);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.HostSettingsLink.Click();
            settingsPage.PageQuotaField.TypeText(numPages.ToString());
            System.Threading.Thread.Sleep(1500);
            settingsPage.UpdateLink.Click();
            System.Threading.Thread.Sleep(5000);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Now try and add a page as an admin. 
            String pageName = "Test Page";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;

            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");

            //Assert that the page was added correctly
            SiteMenu menu = new SiteMenu(homePage);
            Assert.AreEqual(pageName, menu.BreadCrumbSpan.Text);
            Assert.IsTrue(menu.MainMenu.InnerHtml.Contains(pageName));

            //try to add a second page as an admin, this should fail                       
            if (usesRibbonBar)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            System.Threading.Thread.Sleep(4500);

            //Assert that the admin cannot add the page 
            Assert.IsTrue(newPage.PopUpMessageSpan.InnerHtml.Contains("Adding this page will exceed the Page Quota for this site."));

            //Now log in as the host and try and add a page 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            pageName = "hostpage";
            if (usesRibbonBar)
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.PageNameField.Value = pageName;
            newPage.AddPageLink.Click();
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/hostpage.aspx");

            //Assert that the page was added correctly
            Assert.AreEqual(pageName, menu.BreadCrumbSpan.Text);
            Assert.IsTrue(menu.MainMenu.InnerHtml.Contains(pageName));
        }

        [Test]
        public void Change_Control_Panel_Security()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            bool usesRibbonBar = false;

            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            String pageName = "TestPage";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;

            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.ClickViewPermissionForRole("All Users");
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Add A module to the page 
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            string moduleContent = "Unique Text";
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent("", "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent("", "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent("", "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent("", "HTML Pro", moduleContent, 0);

                }
            }
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.AddUserPermissionField.Value = TestUsers.User1.UserName;
            modulePage.AddUserPermissionButton.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            modulePage.ClickAddedUserEditCheckbox(VersionType);
            System.Threading.Thread.Sleep(1500);
            modulePage.UpdateLink.ClickNoWait();

            //Act
            System.Threading.Thread.Sleep(2500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");

            //Assert
            Assert.IsTrue(homePage.ControlPanelElement.Exists);

            //Act
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.UsabillitySectionLink.ClickNoWait();
            settingsPage.PageEditorsControlPanelRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(500);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Assert.IsFalse(homePage.ControlPanelElement.Exists);
        }

        [Test]
        public void Delete_Edit_Portal_Alias()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            string portalAlias;
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            //Create 2 portal aliases
            for (int i = 0; i < 2; i++)
            {
                portalAlias = "newportalalias" + i;
                IISManager.CreateIISApplication(portalAlias, PhysicalPath);
                settingsPage.AdvancedSettingsTab.Click();
                settingsPage.PortalAliasesSectionLink.Click();
                settingsPage.AddNewAliasLink.Click();
                System.Threading.Thread.Sleep(500);
                settingsPage.AliasTextBox.Value = ("localhost/" + portalAlias);
                System.Threading.Thread.Sleep(500);
                if (i == 0)
                {
                    settingsPage.PortalAliasSaveButtonPortal.Click();
                }
                else
                {
                    //settingsPage.PortalAliasSaveButtonPortal2.Click();
                    settingsPage.PortalAliasSaveButtonPortal.Click();
                }
                settingsPage.UpdateLink.ClickNoWait();
                System.Threading.Thread.Sleep(500);
            }

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PortalAliasesSectionLink.Click();
            Assert.IsFalse(settingsPage.GetPortalEditButton(1).Exists);

            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                settingsPage.GetPortalDeleteImage(2).ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            System.Threading.Thread.Sleep(1500);
            portalAlias = "testportalalias";
            IISManager.CreateIISApplication(portalAlias, PhysicalPath);
            settingsPage.GetPortalEditButton(2).Click();
            settingsPage.AliasTextBox.Value = ("localhost/" + portalAlias);
            settingsPage.PortalAliasSaveButtonPortal.Click();
            settingsPage.UpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(2500);
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PortalAliasesSectionLink.Click();
            Assert.IsTrue(settingsPage.PortalAliasTable.InnerHtml.Contains("localhost/" + portalAlias));
            Assert.IsFalse(settingsPage.PortalAliasTable.InnerHtml.Contains("localhost/newPortalAlias0"));
            Assert.IsFalse(settingsPage.PortalAliasTable.InnerHtml.Contains("localhost/newPortalAlias1"));
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo("http://localhost/" + portalAlias);
            System.Threading.Thread.Sleep(2500);
            Assert.IsTrue(ieInstance.Image(Find.ById("dnn_dnnLogo_imgLogo")).Exists);
        }

        [Test]
        public void Disable_Enable_Inline_Editing()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Add A page and module
            String pageName = "TestPage";
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Add A module to the page 
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML Pro");

                }
            }
            ModulePage module = new ModulePage(homePage);
            System.Threading.Thread.Sleep(2000);
            module.ModuleTitleSpan.FireEvent("onmouseover");
            module.ModuleTitleSpan.FireEvent("onmousemove");
            Assert.IsTrue(module.InlineEditButton.Exists);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsButton.ClickNoWait();
            settingsPage.UsabilitySettingsExpandButton.ClickNoWait();
            settingsPage.EnableInlineEditorCheckBox.Checked = false;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            module.ModuleTitleSpan.FireEvent("onmouseover");
            module.ModuleTitleSpan.FireEvent("onmousemove");
            Assert.IsFalse(module.InlineEditButton.Exists);
        }

        [Test]
        public void Change_Control_Panel_Mode()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            bool usesRibbonBar = false;
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            String pageName = "TestPage";
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Assert that the current default is "Edit" mode
            Assert.IsTrue(homePage.ControlPanelModeSelectlist.SelectedOption.Text.Contains("Edit"));

            //Add a user to test control panel mode
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);

            ieInstance.GoTo(SiteURL + "/Home.aspx");
        
            //Add A page for testing
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.ClickViewPermissionForRole("All Users");
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Add A module to the page 
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML Pro");

                }
            }

            ModulePage modulePage = new ModulePage(homePage);
            //Give the user edit permissions for the module
            System.Threading.Thread.Sleep(2000);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            modulePage.InheritPagePermissionsCheckBox.Checked = true;
            modulePage.AddUserPermissionField.TypeText(TestUsers.User1.UserName);
            modulePage.AddUserPermissionButton.Click();
            System.Threading.Thread.Sleep(1500);
            modulePage.ClickAddedUserEditCheckbox(VersionType);
            System.Threading.Thread.Sleep(1500);
            modulePage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.UsabillitySectionLink.ClickNoWait();
            settingsPage.SelectViewModeRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Assert
           // Assert.IsFalse(homePage.EditRadioButton.Checked);
            Assert.IsFalse(homePage.ControlPanelModeSelectlist.SelectedOption.Text.Contains("Edit"));
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            System.Threading.Thread.Sleep(2500);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(homePage.ControlPanelModeSelectlist.Exists);
            //Assert.IsTrue(homePage.GetSelectedItemFromSelecList(homePage.ControlPanelModeSelectlist).Text.Contains("View"));
            Assert.IsFalse(homePage.ControlPanelModeSelectlist.SelectedOption.Text.Contains("Edit"));
            Assert.IsTrue(homePage.ControlPanelModeSelectlist.SelectedOption.Text.Contains("View"));
            //Assert.IsFalse(homePage.EditRadioButton.Checked);
            //Assert.IsTrue(homePage.ViewRadioButton.Checked);
        }

        [Test]
        public void Change_Site_Details()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            string Title = "New Title";
            string Description = "This site is used for automation testing";
            string Keywords = "WatiN, DotNetNuke, UI, Testing";
            string Copyright = "New Test Copyright";

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.SiteTitleField.Value = Title;
            settingsPage.DescriptionField.Value = Description;
            settingsPage.KeywordsField.Value = Keywords;
            settingsPage.CopyrightField.Value = Copyright;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(500);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(ieInstance.Title.Contains(Title));
            Assert.IsTrue(homePage.CopyrightSpan.InnerHtml.Contains(Copyright));
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            Assert.IsTrue(settingsPage.DescriptionField.Text.Equals(Description));
            Assert.IsTrue(settingsPage.KeywordsField.Text.Equals(Keywords));
        }

        [Test]
        public void Change_Splash_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            String pageName = "Splash Page";
            //Create a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.SplashPageSelectList.Select(pageName);
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/LogOff.aspx");

            //Assert
            ieInstance.Close();
            ieInstance = WatiNUtil.OpenIEInstance(SiteURL, SilentMode, IETimeOut, AutoCloseIE, AutoMovePointer);
            System.Threading.Thread.Sleep(5000);
            homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals(pageName));
        }

        [Test]
        public void Change_Home_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            String pageName = "New Home Page";
            //Create a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.PermissionsTabLink.Click();
            newPage.AllUsersViewPermissionCheckbox.ClickNoWait();
            System.Threading.Thread.Sleep(6500);
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.HomePageSelectList.Select(pageName);
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/LogOff.aspx");

            //Assert
            ieInstance.Close();
            ieInstance = WatiNUtil.OpenIEInstance(SiteURL, SilentMode, IETimeOut, AutoCloseIE, AutoMovePointer);
            System.Threading.Thread.Sleep(5000);
            homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals(pageName));
        }

        [Test]
        public void Change_Site_Payment_Settings()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);

            //Act
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PaymentSettingsSectionLink.Click();
            settingsPage.CurrencySelectList.Select("Euros (EUR)");
            settingsPage.PaymentProcessorSelectList.Select("PayPal");
            settingsPage.ProcessorUserIdField.Value = TestUsers.PaymentUser.UserName;
            settingsPage.ProcessorPasswordField.Value = TestUsers.PaymentUser.Password;
            settingsPage.UpdateLink.ClickNoWait();

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PaymentSettingsSectionLink.Click();
            Assert.IsTrue(settingsPage.PaymentProcessorSelectList.SelectedItem.Equals("PayPal"));
            Assert.IsTrue(settingsPage.ProcessorUserIdField.Text.Equals(TestUsers.PaymentUser.UserName));
            Assert.IsTrue(settingsPage.ProcessorPasswordField.Text.Equals(TestUsers.PaymentUser.Password));
            Assert.IsTrue(settingsPage.CurrencySelectList.SelectedItem.Equals("Euros (EUR)"));
        }

        [Test]
        public void Clicking_Go_To_Payment_Processor_Website()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);

            //Act
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.PaymentSettingsSectionLink.Click();
            settingsPage.PaymentProcessorSelectList.Select("PayPal");
            settingsPage.GoToPaymentProcessorLink.Click();

            //Assert
            System.Threading.Thread.Sleep(5000);
            IE popUpWindow = IE.AttachTo<IE>(Find.ByUrl(s => s.Contains("www.paypal.com")));
            Assert.IsTrue(popUpWindow.Title.Contains("PayPal"));
            popUpWindow.Close();
        }

        [Test]
        public void Change_User_Quota()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);

            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);

            //Act
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.HostSectionLink.ClickNoWait();
            settingsPage.UserQuotaField.Value = "3";
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(userPage.UserTable.InnerHtml.Contains(TestUsers.User2.UserName));
            userPage.AddNewUserStartLink.ClickNoWait();
            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("Adding this user will exceed the User Quota for this site."));
            //Try to register a user
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            Assert.IsFalse(homePage.RegisterLink.Exists);
            //Try to add a user as a host
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AddUser(TestUsers.User3.UserName, TestUsers.User3.Password, TestUsers.User3.FirstName, TestUsers.User3.LastName, TestUsers.User3.EmailAddress, TestUsers.User3.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.Click();
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(userPage.UserTable.InnerHtml.Contains(TestUsers.User3.UserName));
        }

        [Test]
        public void Change_User_Registration_Private()
        {

            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);
            
            //Configure EmailAddress for the site
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("test@dnn.com", "localhost");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.SecuritySectionLink.Click();
            settingsPage.PrivateRegistrationRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);
            //Try to register a user
            loginPage.RegisterLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            userPage.UserNameField.Value = TestUsers.Register.UserName;
            userPage.FirstNameField.Value = TestUsers.Register.FirstName;
            userPage.LastNameField.Value = TestUsers.Register.LastName;
            userPage.DisplayNameField.Value = TestUsers.Register.DisplayName;
            userPage.EmailField.Value = TestUsers.Register.EmailAddress;
            userPage.PasswordField.Value = TestUsers.Register.Password;
            userPage.ConfirmPasswordField.Value = TestUsers.Register.Password;
            userPage.RegisterButton.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("An e-mail with your details has been sent to the portal administrator for verification."));
            Assert.IsTrue(Directory.GetFiles(TestEmailPath).Length == 2);
            Assert.IsFalse(string.IsNullOrEmpty(Directory.GetFiles(TestEmailPath)[0]));
            Assert.IsFalse(string.IsNullOrEmpty(Directory.GetFiles(TestEmailPath)[1]));

            //Authorize the user 
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AllDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            userPage.GetUserEditButton(TestUsers.Register.DisplayName).Click();
            userPage.AuthorizeUserLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);

            Assert.IsTrue(Directory.GetFiles(TestEmailPath).Length == 3);
            Assert.IsFalse(string.IsNullOrEmpty(Directory.GetFiles(TestEmailPath)[2]));

            //Delete The EmailAddress files
            homePage.DeleteFilesInTestEmails();
        }

        [Test]
        public void Change_User_Registration_Public()
        {

            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

            
            //Configure EmailAddress for the site
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("test@dnn.com", "localhost");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.SecuritySectionLink.Click();
            settingsPage.PublicRegistrationRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);
            //Try to register a user
            loginPage.RegisterLink.Click();
            System.Threading.Thread.Sleep(2000);
            userPage.UserNameField.Value = TestUsers.Register.UserName;
            userPage.FirstNameField.Value = TestUsers.Register.FirstName;
            userPage.LastNameField.Value = TestUsers.Register.LastName;
            userPage.DisplayNameField.Value = TestUsers.Register.DisplayName;
            userPage.EmailField.Value = TestUsers.Register.EmailAddress;
            userPage.PasswordField.Value = TestUsers.Register.Password;
            userPage.ConfirmPasswordField.Value = TestUsers.Register.Password;
            userPage.RegisterButton.Click();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(loginPage.RegisterLink.Text.StartsWith(TestUsers.Register.DisplayName));

            Assert.IsTrue(Directory.GetFiles(TestEmailPath).Length == 2);
            Assert.IsFalse(string.IsNullOrEmpty(Directory.GetFiles(TestEmailPath)[0]));
            Assert.IsFalse(string.IsNullOrEmpty(Directory.GetFiles(TestEmailPath)[1]));

            //Delete The EmailAddress files
            homePage.DeleteFilesInTestEmails();
        }

        [Test]
        public void Add_Premium_Modules()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");

            //Act 
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.HostSectionLink.Click();
            System.Threading.Thread.Sleep(1500);
            //Select Search Admin with a value of 43
            settingsPage.AvailablePremiumModulesSelectList.SelectByValue("43");
            settingsPage.AddModuleLink.ClickNoWait();
            settingsPage.UpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            settingsPage.AdvancedSettingsTab.Click();
            //settingsPage.HostSectionLink.Click();
            System.Threading.Thread.Sleep(2500);
            Assert.IsFalse(settingsPage.AvailablePremiumModulesSelectList.Option(Find.ByValue("43")).Exists);
            Assert.IsTrue(settingsPage.SelectedPremiumModuleSelectList.Option(Find.ByValue("43")).Exists);
        }

        [Test]
        public void Deleting_Premium_Modules()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");

            //Act 
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.HostSectionLink.Click();
            settingsPage.SelectedPremiumModuleSelectList.SelectByValue("14");
            settingsPage.RemoveModuleLink.ClickNoWait();
            settingsPage.UpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            settingsPage.AdvancedSettingsTab.Click();
            settingsPage.HostSectionLink.Click();
            Assert.IsTrue(settingsPage.AvailablePremiumModulesSelectList.Option(Find.ByValue("14")).Exists);
            Assert.IsFalse(settingsPage.SelectedPremiumModuleSelectList.Option(Find.ByValue("14")).Exists);
        }


        [Test]
        public void Change_User_Registration_Verified()
        {

            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            //Delete any files in the test EmailAddress folder
            homePage.DeleteFilesInTestEmails();

            //Edit the web.config file so that Emails are sent to a local folder
            WebConfigManager.UpdateConfig(PhysicalPath);

           
            //Configure EmailAddress for the site
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);
            ieInstance.GoTo(SiteURL + "/tabid/16/portalid/0/Default.aspx");
            HostSettingsPage hostSettings = new HostSettingsPage(homePage);
            hostSettings.SetSMTPSettings("test@dnn.com", "localhost");

            //Act 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsTab.ClickNoWait();
            settingsPage.SecuritySectionLink.Click();
            settingsPage.VerifiedRegistrationRadioButton.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();

            //Assert 
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            UserPage userPage = new UserPage(homePage);
            //Try to register a user
            loginPage.RegisterLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            userPage.UserNameField.Value = TestUsers.Register.UserName;
            userPage.FirstNameField.Value = TestUsers.Register.FirstName;
            userPage.LastNameField.Value = TestUsers.Register.LastName;
            userPage.DisplayNameField.Value = TestUsers.Register.DisplayName;
            userPage.EmailField.Value = TestUsers.Register.EmailAddress;
            userPage.PasswordField.Value = TestUsers.Register.Password;
            userPage.ConfirmPasswordField.Value = TestUsers.Register.Password;
            userPage.RegisterButton.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            Assert.IsTrue(userPage.PopUpMessageSpan.InnerHtml.Contains("An e-mail with your verification code has been sent to your e-mail address:"));

            var emailFileName = Directory.GetFiles(@TestEnvironment.TestEmailPath)[1];
            string verificationEmailContent = File.ReadAllText(emailFileName);
            if (verificationEmailContent.Contains("X-Receiver: " + TestUsers.Admin.Email))
            {
                emailFileName = Directory.GetFiles(@TestEnvironment.TestEmailPath)[0];
                verificationEmailContent = File.ReadAllText(emailFileName);
            }
            string verificationUrlRegex = SiteURL.ToLower() + @"/default\.aspx\?ctl=Login&username=register&verificationcode=\d+-\d+";
            verificationEmailContent = ConvertEmailContentFromBase64ToUnicode(verificationEmailContent, emailFileName);
            Match match = Regex.Match(@verificationEmailContent, @verificationUrlRegex);

            Assert.IsTrue(match.Success, "Could not find verification link!");
            string verificationUrl = match.Value;

            ieInstance.GoTo(verificationUrl);
            loginPage.Password.Value = TestUsers.Register.Password;
            loginPage.LoginButton.Click();
            Assert.IsTrue(loginPage.RegisterLink.Text.StartsWith(TestUsers.Register.DisplayName));

           // Delete The Email files
            homePage.DeleteFilesInTestEmails();
        }


        [Test]
        public void Change_Control_Panel_Visibility()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            String pageName = "TestPage";
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);

            //Assert that the current default is Maximized
            Assert.IsTrue(homePage.MinimiseControlPanelImage.Src.Contains("collapse.gif"));

            //Add a user to test control panel mode
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);

            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Add A page for testing
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.UserPermissionField.Value = TestUsers.User1.UserName;
            newPage.AddUserPermissionLink.ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            newPage.AddedUserEditPermissionCheckBox.Click();
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

             //Act 
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            System.Threading.Thread.Sleep(500);
            settingsPage.AdvancedSettingsButton.ClickNoWait();
            settingsPage.UsabilitySettingsExpandButton.ClickNoWait();
            settingsPage.SelectControlPanelMinimised.Checked = true;
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(3000);

            //Assert
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(homePage.MaximiseControlPanelImage.Src.Contains("expand.gif"));
            Assert.IsFalse(homePage.MaximiseControlPanelImage.Src.Contains("collapse.gif"));
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Assert.IsTrue(homePage.MaximiseControlPanelImage.Src.Contains("expand.gif"));
            Assert.IsFalse(homePage.MaximiseControlPanelImage.Src.Contains("collapse.gif"));
        }


        [Test]
        public void Change_Portal_Time_Zone()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            String pageName = "TestPage";
            loginPage.LoginUser(TestUsers.Host.UserName, TestUsers.Host.Password);

            //Install a forum module to the site
            ieInstance.GoTo(SiteURL + "/tabid/36/portalid/0/language/en-US/Default.aspx");
            ExtensionsPage extensionsPage = new ExtensionsPage(homePage);
            extensionsPage.InstallExtension(ForumPackagePath);

            //Add a user
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(2000);
            userPage.AllDisplayLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Change the users time zone
            userPage.GetUserEditButton(TestUsers.User1.DisplayName).ClickNoWait();
            UserProfilePage profilePage = new UserProfilePage(homePage);
            profilePage.ManageProfileLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);
            profilePage.TimeZoneSelectList.Select("(UTC 00:00) Dublin, Edinburgh, Lisbon, London");
            profilePage.ProfileUpdateLink.ClickNoWait();

            //Add a page for testing
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.PageNameField.Value = pageName;
            newPage.PageTemplateSelect.Select("None Specified");
            newPage.ClickViewPermissionForRole("All Users");
            newPage.AddPageLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Add a forum module to the page
            if (!usesRibbonBar)
            {
                controlPanel.AddModuleToPage("", "Forum");
            }
            else
            {
                ribbonBar.AddModuleToPage("", "Forum", "All Categories");
            }

            //Act 
            //Change the time zone
            DateTime dateTime = DateTime.Now;
            TimeZone timeZone = TimeZone.CurrentTimeZone;
            int utcOffset = timeZone.GetUtcOffset(dateTime).Hours;
            if (timeZone.IsDaylightSavingTime(dateTime))
            {
                utcOffset = utcOffset - 1;
            }
            utcOffset = utcOffset + 2;
            string UTCstring = @"\(UTC " + utcOffset.ToString("00") + @":00\) .*";
            Regex reg = new Regex(@UTCstring);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/Admin/SiteSettings.aspx");
            SiteSettingsPage settingsPage = new SiteSettingsPage(homePage);
            settingsPage.AdvancedSettingsButton.ClickNoWait();
            settingsPage.OtherSettingsExpandImage.ClickNoWait();
            settingsPage.TimeZoneSelectList.Select(reg);
            settingsPage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Create a new user
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            userPage.AddUser(TestUsers.User2.UserName, TestUsers.User2.Password, TestUsers.User2.FirstName, TestUsers.User2.LastName, TestUsers.User2.EmailAddress, TestUsers.User2.DisplayName);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            loginPage.LogoffUser();
            //Navigate to the forum page
            loginPage.LoginUser(TestUsers.User2.UserName, TestUsers.User2.Password);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            System.Threading.Thread.Sleep(1500);
            ForumPage forum = new ForumPage(homePage);
            forum.GeneralDiscussionLink.ClickNoWait();
            forum.NewThreadLink.ClickNoWait();
            forum.ForumSubjectField.Value = "test post 1";
            forum.BasicTextBoxEditorRadioButton.Checked = true;
            forum.ForumContentField.Value = "This is a test.";
            forum.SubmitLink.ClickNoWait();
            //Use the current time to find out when the users post time should be
            dateTime = DateTime.Now;
            System.Threading.Thread.Sleep(1000);
            int postMinutes = dateTime.Minute;
            int postHour = dateTime.Hour + 2;
            postHour = postHour % 12;
            string postTime = postHour + ":" + postMinutes.ToString("00");
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            //Assert that the users post time is correct
            Assert.IsTrue(forum.ForumPostTimeSpan.InnerHtml.Contains(postTime), postTime + " is not the post time, utcoffset: " + utcOffset + " postHour: " + postHour);

            loginPage.LogoffUser();
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            postHour = postHour - utcOffset;
            postHour = postHour % 12;
            postTime = postHour + ":" + postMinutes.ToString("00");
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Assert.IsTrue(forum.ForumPostTimeSpan.InnerHtml.Contains(postTime), postTime + " is not the post time, utcoffset: " + utcOffset + " postHour: " + postHour);
        }
        
        #endregion

        private string ConvertEmailContentFromBase64ToUnicode(string emailContent, string emailFileName)
        {
            //Replace any new link characters
            emailContent.Replace(Environment.NewLine, " ");

            //Separate the EmailAddress content from the EmailAddress information
            string contentLineRegex = "(?<=base64).*$";
            Match match = Regex.Match(@emailContent, contentLineRegex, RegexOptions.Singleline);
            Assert.IsTrue(match.Success, "Could not find content Line! Looking in file: " + emailFileName);

            //Convert the EmailAddress content
            emailContent = match.Value;
            byte[] b = System.Convert.FromBase64String(emailContent);
            String decodedEmailContent = System.Text.ASCIIEncoding.ASCII.GetString(b);
            return decodedEmailContent;
        }
    }
}